﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace nGSO
{
    public class DefaultNeighboursLocalizator : INeighboursLocalizator
    {
        #region INeighboursLocalizator Members

        public void SetAgentNeighbors(Agent agent, IEnumerable<Agent> agents, int dims)
        {
            // should be replaced with r-tree indexing http://en.wikipedia.org/wiki/R-tree
            // http://sourceforge.net/projects/cspatialindexrt/
            // wartosc funkcji odległości
            double[] agentLoc = agent.Loc;

            foreach (Agent potentialNeighbor in agents.Where(s => s.Id != agent.Id))
            {
                double euclideanDistance = agent.GetDistanceTo(potentialNeighbor, dims);
                
                double currentAgentRange = agent.NeighborhoodRange;

                if ((euclideanDistance < currentAgentRange) && (agent.Luciferin < potentialNeighbor.Luciferin))
                    agent.Neighbors.Add(potentialNeighbor);
            }
        }

        #endregion
    }
}
